package com.example.myproject.controller;

import com.example.myproject.dto.CommonResponse;
import com.example.myproject.dto.comment.CommentRequest;
import com.example.myproject.dto.comment.CommentResponse;
import com.example.myproject.dto.comment.CommentsListResponse;
import com.example.myproject.service.CommentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/values")
public class CommentController {

    @Autowired
    private CommentService commentService;

    @PostMapping("/comment")
    public CommonResponse<CommentResponse> postComment(@RequestBody CommentRequest req) {
        // 用户登录验证将通过Spring Security框架处理
        CommentResponse resp = commentService.postComment(req);
        return CommonResponse.success(resp);
    }

    @GetMapping("/torrent/{torrentId}/comments")
    public CommonResponse<CommentsListResponse> getComments(
            @PathVariable("torrentId") Integer torrentId,
            @RequestParam(value = "sort", defaultValue = "newest") String sort,
            @RequestParam(value = "page", defaultValue = "1") Integer page,
            @RequestParam(value = "per_page", defaultValue = "10") Integer perPage) {
        // 用户登录验证将通过Spring Security框架处理
        CommentsListResponse resp = commentService.getComments(torrentId, sort, page, perPage);
        return CommonResponse.success(resp);
    }
}